<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/js/jquery-3.4.1.js"></script>
    <script type="text/javascript">
        function fileLoad(ele){
            var name = $(ele).val();
            var files = $(ele)[0].files[0];
            var start = name.lastIndexOf("\\");//获得字符串的开始位置
            //alert(name.substring(start+1));
            fileNameReal.value=name.substring(start+1);
        }
        $(function () {
            var $input =  $("#upLoad");
            // ①为input设定change事件
            $input.change(function () {
                //    ②如果value不为空，调用文件加载方法
                if($(this).val() != ""){
                    fileLoad(this);
                }
            })
        })

        function wei() {
//        document.("表单的name值").action
//        document.("表单的name值").submit
            document.form4.action = "{:U('/system/attachment/upload_spring')}";
            document.form4.submit();
        }
    </script>
</head>
<body>
<h1>采用流的方式上传文件</h1>
<form name="form1" action="/system/attachment/upload_01" method="post" enctype="multipart/form-data">
    <input type="file" name="file_01"/>
    <input type="submit" value="fileupload"/>
</form>
<br>
<h1>采用multipart提供的file.transfer方法上传文件1</h1>
<form name="form2" action="/system/attachment/upload_02" method="post" enctype="multipart/form-data">
    <input type="file" name="file_02"/>
    <input type="submit" value="fileupload"/>
</form>
<br>
<h1>采用multipart提供的file.transfer方法上传文件2</h1>
<form name="form3" action="/system/attachment/upload_03" method="post" enctype="multipart/form-data">
    <input type="file" name="file_03" >
    <input type="submit" value="fileupload"/>
</form>
<br>
<h1>使用spring MVC提供的方法上传文件</h1>
<!--<form name="form4" action="/system/attachment/upload_spring" method="post" enctype="multipart/form-data">-->
    <!--<input type="file" name="file_03" id="upLoad">-->
    <!--<input type="text" name="fileNameReal" id="fileNameReal">-->
    <!--<input type="submit" value="提交"/>-->
<!--</form>-->
<form name="form4" action="/system/attachment/upload_spring" method="post" enctype="multipart/form-data">
    <input type="file" name="file_03" id="upLoad">
    <input type="text" name="fileNameReal" id="fileNameReal">
    <!--<input type="submit" value="提交"/>-->
    <button οnclick="wei()"/>上传</button>
</form>
</body>
</html>